home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Think Class Libraries / WASTE TCL 1.8 / WASTE TCL 1.8 ƒ / CWASTEStyleTask.cp < prev    next >
Encoding:
Text File  |  1995-11-12  |  5.7 KB  |  258 lines  |  [TEXT/MMCC]

  1. /*
  2.  *
  3.  *    File:        CWASTEStyleTask.cp
  4.  *    Module:        CWASTEStyleTask method definitions
  5.  *    System:        Mark's Class Library
  6.  *    Evironment:    MacOS 7.0/THINK C 6.0/TCL 1.1.3
  7.  *    Author:        Mark Alldritt
  8.  *
  9.  *
  10.  *        Copyright © 1994    All Rights Reserved
  11.  *        Mark Alldritt
  12.  *        1571 Deep Cove Road
  13.  *        N. Vancouver, B.C. CANADA
  14.  *
  15.  *    
  16.  *    Description:
  17.  *
  18.  *  This class modifies the CTextStyleTask to allow it to work with CWASTEPane.
  19.  *
  20.  *
  21.  *    Acknowledgemets:
  22.  *
  23.  *    None.
  24.  *
  25.  *
  26.  *    Notes:
  27.  *
  28.  *    This source file depends on the "Scriptable TCL+MacTraps" pre-compiled header for all TCL
  29.  *    definitions.
  30.  *
  31.  *
  32.  *    Edit History:
  33.  *
  34.  *    V1-0.0    Mark Alldritt    10-May-1994
  35.  *    - Initial version of module.
  36.  *
  37.  *            Adapted to THINK C / TCL 1.1.3     (Roms, 95/11/08)
  38.  */
  39.  
  40.  
  41. //#include "GlobalVars.h"
  42. #include "CWASTEText.h"
  43. #include "CWASTEStyleTask.h"
  44.  
  45.  
  46. extern RGBColor RGBBlack;
  47. extern RGBColor RGBRed;
  48. extern RGBColor RGBGreen;
  49. extern RGBColor RGBBlue;
  50. extern RGBColor RGBCyan;
  51. extern RGBColor RGBMagenta;
  52. extern RGBColor RGBYellow;
  53.  
  54.  
  55. #ifndef THINK_C
  56. CWASTEStyleTask::CWASTEStyleTask(CWASTEText *aTextPane, 
  57.                                  long aStyleCmd, short firstTaskIndex)
  58.     : CTextStyleTask( aTextPane, aStyleCmd, firstTaskIndex)
  59. {
  60.     long selStart, selEnd;
  61. #else
  62. void CWASTEStyleTask::IWASTEStyleTask(CWASTEText *aTextPane, 
  63.                                  long aStyleCmd, short firstTaskIndex)
  64. {
  65.     long selStart, selEnd;
  66.     
  67.     CTextStyleTask:: ITextStyleTask( aTextPane, aStyleCmd, firstTaskIndex);
  68. #endif // THINK_C
  69.     
  70.     oldStyles = NULL;
  71.     
  72.     itsTextPane->GetSelection( &selStart, &selEnd);
  73.     this->selStart = selStart;
  74.     this->selEnd = selEnd;
  75.     
  76. }    /* CWASTEStyleTask::IWASTEStyleTask */
  77.  
  78.  
  79. #ifndef THINK_C
  80. CWASTEStyleTask::~CWASTEStyleTask( void)
  81. #else
  82. void CWASTEStyleTask::Dispose(void)
  83. #endif // THINK_C
  84. {
  85.  
  86. #if TCL_VERSION >= 0x02000000
  87.     TCLForgetHandle( oldStyles);
  88. #else
  89.     ForgetHandle(oldStyles);
  90. #endif
  91.     
  92. #ifdef THINK_C
  93.     CTextStyleTask::Dispose();
  94. #endif
  95.  
  96. }
  97.  
  98. /******************************************************************************
  99.  Do  MF nov -- we have to alter this for cmdJustify and color
  100.  
  101.      Saves the original formatting, then performs the user's formatting command
  102.      on the text pane.
  103. ******************************************************************************/
  104.  
  105. void  CWASTEStyleTask::Do()
  106.     {
  107.  
  108.      SaveStyle();
  109.  
  110.     oldAlignCmd = itsTextPane->GetAlignCmd();
  111.     oldSpacingCmd = itsTextPane->GetSpacingCmd();
  112.     
  113.     switch (styleCmd)
  114.         {
  115.         case cmdBlack:
  116.                 ((CWASTEText*)itsTextPane)->SetFontColor(&RGBBlack);
  117.                 styleAttribute = doColor;
  118.                 break;
  119.         case cmdRed:
  120.                 ((CWASTEText*)itsTextPane)->SetFontColor(&RGBRed);
  121.                 styleAttribute = doColor;
  122.                 break;
  123.         case cmdGreen:
  124.                 ((CWASTEText*)itsTextPane)->SetFontColor(&RGBGreen);
  125.                 styleAttribute = doColor;
  126.                 break;
  127.         case cmdBlue:
  128.                 ((CWASTEText*)itsTextPane)->SetFontColor(&RGBBlue);
  129.                 styleAttribute = doColor;
  130.                 break;
  131.         case cmdCyan:
  132.                 ((CWASTEText*)itsTextPane)->SetFontColor(&RGBCyan);
  133.                 styleAttribute = doColor;
  134.                 break;
  135.         case cmdMagenta:
  136.                 ((CWASTEText*)itsTextPane)->SetFontColor(&RGBMagenta);
  137.                 styleAttribute = doColor;
  138.                 break;
  139.         case cmdYellow:
  140.                 ((CWASTEText*)itsTextPane)->SetFontColor(&RGBYellow);
  141.                 styleAttribute = doColor;
  142.                 break;
  143.                 
  144.     
  145.         case cmdJustify:
  146.                 itsTextPane->SetAlignCmd(styleCmd);
  147.                 styleAttribute = doAlign;
  148.                 break;
  149.         default:
  150.             inherited::Do();
  151.         }
  152.     }
  153.  
  154.  
  155.  
  156. /******************************************************************************
  157.  Undo
  158.  
  159.      Undo the previously applied formatting. This method swaps the current and
  160.      previous styles, so it can perform both undo and redo.
  161. ******************************************************************************/
  162.  
  163. void CWASTEStyleTask::Undo( void)
  164. {
  165.     StScrpHandle    swapStyles, newStyles;
  166.     CWASTEText        *styleText = (CWASTEText*) itsTextPane;
  167.     
  168.     swapStyles = newStyles = NULL;
  169.  
  170. #if TCL_VERSION >= 0x02000000
  171.     try_
  172. #else
  173.     TRY
  174. #endif
  175.     {
  176.         if (styleAttribute < doAlign)
  177.         {
  178.             
  179.             itsTextPane->Prepare();    
  180.             itsTextPane->SetSelection( selStart, selEnd, TRUE);
  181.             
  182.             swapStyles = oldStyles;        /* save the current styling        */
  183.             oldStyles = NULL;
  184.             
  185.             SaveStyle();
  186.         
  187.             newStyles = oldStyles;
  188.             oldStyles = swapStyles;        /* restore the previous styling */
  189.             swapStyles = NULL;
  190.         
  191.             RestoreStyle();
  192.             
  193.             ForgetHandle( oldStyles);
  194.             
  195.             oldStyles = newStyles;        /* swap current and previous    */
  196.             
  197.             styleText->SetSpacingCmd( styleText->GetSpacingCmd());
  198.             styleText->SetWholeLines( styleText->GetWholeLines());
  199.             styleText->AdjustBounds();
  200.             
  201.             undone = !undone;
  202.  
  203.         }
  204.         else inherited::Undo();
  205.     }
  206. #if TCL_VERSION >= 0x02000000
  207.     catch_all_()
  208. #else
  209.     CATCH
  210. #endif
  211.     {
  212.         ForgetHandle( oldStyles);
  213.         ForgetHandle( newStyles);
  214.         ForgetHandle( swapStyles);
  215.     }
  216. #if TCL_VERSION >= 0x02000000
  217.     end_try_;
  218. #else
  219.     ENDTRY;
  220. #endif
  221.  
  222. }    /* CWASTEStyleTask::Undo */
  223.  
  224. /******************************************************************************
  225.  SaveStyle
  226.  
  227.      Saves the current styling into oldStyles.
  228. ******************************************************************************/
  229.  
  230. void CWASTEStyleTask::SaveStyle( void)
  231. {
  232.     oldStyles = NULL;    /* GetStyleScrap may fail    */
  233.     
  234.     oldStyles = ((CWASTEText*)itsTextPane)->GetTheStyleScrap();
  235.  
  236. }    /* CWASTEStyleTask::SaveStyle */
  237.  
  238. /******************************************************************************
  239.  RestoreStyle
  240.  
  241.      Restores the saved styles from oldStyles back to the text.
  242. ******************************************************************************/
  243.  
  244. void CWASTEStyleTask::RestoreStyle( void)
  245. {
  246.     if (styleAttribute < doAlign)
  247.     {    
  248.         /* +++ work around problem with redoing cmdPlain on styled text? */
  249.         if ((styleCmd == cmdPlain) && (undone == TRUE))
  250.             itsTextPane->SetFontStyle( NOTHING);
  251.         else
  252.             ((CWASTEText *) itsTextPane)->SetTheStyleScrap(selStart, selEnd, oldStyles, TRUE);        
  253.     }
  254.     else
  255.         inherited::RestoreStyle();
  256.         
  257. }    /* CWASTEStyleTask::RestoreStyle */
  258.